using System;

namespace OracleInternal.Secure.Network
{
	public abstract class DataIntegrityAlgorithm
	{
		private static int m_a = 5;

		private AES b;

		private RC4 c;

		private bool d;

		private byte[] e;

		private byte[] f;

		private string g;

		internal IClass_d h;

		public void init(byte[] k, byte[] iv, string a)
		{
			this.a(k, iv, a);
		}

		private void a(byte[] A_0, byte[] A_1, string A_2)
		{
			h.b();
			g = A_2;
			if (g == "SHA256" || g == "SHA384" || g == "SHA512")
			{
				d = true;
			}
			if (d)
			{
				b = new AES(1, 1, DataIntegrityAlgorithm.m_a, A_0, A_1, A_5: true);
			}
			else
			{
				c = new RC4(DataIntegrityAlgorithm.m_a * 8, A_0, A_1, A_3: true);
			}
			f = new byte[size()];
		}

		public bool compare(byte[] b, int l, byte[] xs, int off)
		{
			return a(b, l, xs, off);
		}

		private bool a(byte[] A_0, int A_1, byte[] A_2, int A_3)
		{
			byte[] A_4 = new byte[size()];
			if (d)
			{
				if (e != null)
				{
					Buffer.BlockCopy(e, 0, A_4, 0, e.Length);
					e = null;
				}
				e = b.encrypt(A_4, 1);
			}
			else
			{
				e = c.decrypt(A_4);
			}
			if (d)
			{
				h.b(A_0, 0, A_1, e, e.Length, ref A_4);
			}
			else
			{
				h.b();
				h.b(A_0, 0, A_1);
				h.b(e, 0, e.Length);
				h.b(A_4, 0);
			}
			bool result = false;
			for (int i = 0; i < size(); i++)
			{
				if (A_4[i] != A_2[A_3 + i])
				{
					result = true;
					break;
				}
			}
			return result;
		}

		public byte[] compute(byte[] s, int off, int l)
		{
			return a(s, off, l);
		}

		private byte[] a(byte[] A_0, int A_1, int A_2)
		{
			if (A_0.Length - A_1 < A_2)
			{
				return null;
			}
			byte[] array = null;
			byte[] A_3 = new byte[size()];
			if (d)
			{
				array = b.encrypt(f, 2);
				Buffer.BlockCopy(array, 0, f, 0, array.Length);
				h.b(A_0, A_1, A_2, array, array.Length, ref A_3);
				return A_3;
			}
			array = c.encrypt(f);
			h.b();
			h.b(A_0, A_1, A_2);
			h.b(array, 0, array.Length);
			h.b(array, 0);
			return array;
		}

		public int takeSessionKey(byte[] key, byte[] iv)
		{
			try
			{
				if (!d)
				{
					c.setSessionKey(key, iv);
				}
				else
				{
					b.setSessionKey(key, iv);
					f = new byte[size()];
					e = null;
				}
			}
			catch (Exception)
			{
			}
			return 0;
		}

		public void renew()
		{
			if (d)
			{
				b.renewKey();
			}
			else
			{
				c.a();
			}
		}

		public int size()
		{
			return h.a();
		}
	}
}
